home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / fpu881 / src6.zoo / atan2.c < prev    next >
C/C++ Source or Header  |  1991-09-24  |  3KB  |  112 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FUNCTION
  23.  *
  24.  *    atan2   double precision arc tangent of two arguments
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    atan2
  29.  *    machine independent routines
  30.  *    trigonometric functions
  31.  *    math libraries
  32.  *
  33.  *  DESCRIPTION
  34.  *
  35.  *    Returns double precision arc tangent of two
  36.  *    double precision floating point arguments ( atan(Y/X) ).
  37.  *
  38.  *  USAGE
  39.  *
  40.  *    double atan2(x,y)
  41.  *    double x;
  42.  *    double y;
  43.  *
  44.  *  REFERENCES
  45.  *
  46.  *    Fortran 77 user's guide, Digital Equipment Corp. pp B-4.
  47.  *
  48.  *  RESTRICTIONS
  49.  *
  50.  *    Note that the argument usage is exactly the reverse of the
  51.  *    common FORTRAN usage where atan2(x,y) computes atan(x/y).
  52.  *    The usage here is less confusing than remembering that x is
  53.  *    really y and y is really x.
  54.  *
  55.  *    For precision information refer to documentation of the
  56.  *    other floating point library routines called.
  57.  *    
  58.  *  PROGRAMMER
  59.  *
  60.  *    Fred Fish
  61.  *    Tempe, Az 85281
  62.  *
  63.  *  INTERNALS
  64.  *
  65.  *    Computes atan(y/x) from:
  66.  *
  67.  *        1.    If x = 0 then
  68.  *            atan(x,y) = PI/2 * (sign(y))
  69.  *
  70.  *        2.    If x > 0 then
  71.  *            atan(x,y) = atan(y/x)
  72.  *
  73.  *        3.    If x < 0 then atan2(x,y) =
  74.  *            PI*(sign(y)) + atan(y/x)
  75.  *
  76.  */
  77.  
  78. #include <stdio.h>
  79. #include <pmluser.h>
  80. #include "pml.h"
  81.  
  82. /* mjr++ */
  83. static unsigned long
  84.     __notanumber[2] = { 0x7fffffffL, 0xffffffffL }; /* ieee NAN */
  85. #define NAN  (*((double *)&__notanumber[0]))
  86.  
  87.  
  88. double atan2 (x, y)
  89. double x;
  90. double y;
  91. {
  92.     double result;
  93.     extern double sign();
  94.     extern double atan();
  95.  
  96.     ENTER ("atan2");
  97.     DEBUG4 ("atan2in", "x = %le y = %le", x, y);
  98. /* mjr++ */
  99.     if(x == NAN) return NAN;
  100.  
  101.     if (x == 0.0) {
  102.     result = sign (HALFPI, y);
  103.     } else if (x > 0.0) {
  104.     result = atan (y/x);
  105.     } else {
  106.     result = atan (y/x) + sign (PI, y);
  107.     }
  108.     DEBUG3 ("atan2out", "result %le", result);
  109.     LEAVE ();
  110.     return (result);
  111. }
  112.